package com.soft.mapper;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.soft.entity.Goods;
import com.soft.entity.Money;
@SpringBootTest
public class GoodsMapperTest {
	@Autowired
	private GoodsMapper goodsMapper;
	@Test
	public void testSelect() {
		List<Goods> deptList=goodsMapper.selectList(null);
		for(int i=0;i<deptList.size();i++) {
			System.out.print(deptList.get(i).getGid()+" ");
			System.out.print(deptList.get(i).getGname()+" ");
			System.out.print(deptList.get(i).getGprice()+" ");
			System.out.println();
		}
	}
	@Test
	public void insertTest() {
		Goods goods=new Goods();
		goods.setGname("aa");
		goods.setGprice("10001");
		goodsMapper.insert(goods);
	}
	@Test
	public void updateTest() {
		Goods goods=new Goods();
		goods.setGid((long)1);
		goods.setGname("aaa");
		goods.setGprice("10002");
		goodsMapper.updateById(goods);
		
	}
	@Test
	public void deleteTest() {
		Goods goods=new Goods();
		goods.setGid((long)3);
		goodsMapper.deleteById(goods);
		
	}
	@Test
	public void deleteQueryTest() {
		QueryWrapper<Goods> qw = new QueryWrapper<>();
		qw.eq("goods_name", "aaa");
		goodsMapper.delete(qw);
	}
	@Test
	public void updateQueryTest() {
		UpdateWrapper<Goods> uw = new UpdateWrapper<>();
		uw.gt("Goods_price", 10000);
		Goods goods=new Goods();
		goods.setGprice("10000");
		goodsMapper.update(goods,uw);
	}
	@Test
	public void selectOneTest() {
		Goods goods = goodsMapper.selectById(2);
		System.out.println(goods.getGname());
	}
	@Test
	public void selectTweTest() {
		QueryWrapper<Goods> qw = new QueryWrapper<>();
		qw.gt("goods_id", 1);
		try {
		Goods goods = goodsMapper.selectOne(qw);
		System.out.println(goods.getGname());
		}catch(Exception e) {
			System.out.println("too many date");
		}
	}
	

}